/*
  ******************************************************************************
  * @file    apt32f172_syscon.c
  * @author  APT AE Team
  * @version V1.12
  * @date    2019/03/08
  ******************************************************************************
  *THIS SOFTWARE WHICH IS FOR ILLUSTRATIVE PURPOSES ONLY WHICH PROVIDES 
  *CUSTOMER WITH CODING INFORMATION REGARDING THEIR PRODUCTS.
  *APT CHIP SHALL NOT BE HELD RESPONSIBILITY ADN LIABILITY FOR ANY DIRECT, 
  *INDIRECT DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT OF 
  *SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION 
  *CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.AND APT CHIP RESERVES 
  *THE RIGHT TO MAKE CHANGES IN THE SOFTWARE WITHOUT NOTIFICATION
  ******************************************************************************
  */

/* Define to prevent recursive inclusion -------------------------------------*/ 
#include "apt32f172_syscon.h"
/* defines -------------------------------------------------------------------*/
volatile U8_T SYSCON_ISOSCSTFlag=0;
volatile U8_T SYSCON_IMOSCSTFlag=0;
volatile U8_T SYSCON_EMOSCSTFlag=0;
volatile U8_T SYSCON_SYSCLKSTFlag=0;
volatile U8_T SYSCON_IWDTINTFlag=0;
volatile U8_T SYSCON_LVDINTFlag=0;
volatile U8_T SYSCON_EM_CMFAILFlag=0;
volatile U8_T SYSCON_EM_CMRCVFlag=0;
volatile U8_T SYSCON_CMD_ERRFlag=0;
/* externs--------------------------------------------------------------------*/

/*************************************************************/
//Deinitializes the syscon registers to their default reset
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/    
void SYSCON_RST_VALUE(void)									//reset value
{
	SYSCON->IDCCR=SYSCON_IDCCR_RST;
	SYSCON->GCER=SYSCON_GCER_RST;
	SYSCON->GCDR=SYSCON_GCDR_RST;
	SYSCON->SCLKCR=SYSCON_SCLKCR_RST;
	SYSCON->PCLKCR=SYSCON_PCLKCR_RST;
	SYSCON->PCER0=SYSCON_PCER0_RST;
	SYSCON->PCDR0=SYSCON_PCDR0_RST;
	SYSCON->PCSR0=SYSCON_PCSR0_RST;
	SYSCON->PCER1=SYSCON_PCER1_RST;
	SYSCON->PCDR1=SYSCON_PCDR1_RST;
	SYSCON->PCSR1=SYSCON_PCSR1_RST;
	SYSCON->OSTR=SYSCON_OSTR_RST;
	SYSCON->LVDCR=SYSCON_LVDCR_RST;
	SYSCON->CLCR=SYSCON_CLCR_RST;
	SYSCON->PWRCR=SYSCON_PWRCR_RST;			
	//SYSCON->OPT4=SYSCON_OPT4_RST;
	//SYSCON->OPT3=SYSCON_OPT3_RST;
	//SYSCON->OPT2=SYSCON_OPT2_RST;
	//SYSCON->OPT1=SYSCON_OPT1_RST;
	//SYSCON->OPT0=SYSCON_OPT0_RST;
	SYSCON->IECR=SYSCON_IECR_RST;
	SYSCON->IDCR=SYSCON_IDCR_RST;
	SYSCON->IMSR=SYSCON_IMSR_RST;
	SYSCON->IAR=SYSCON_IAR_RST;
	SYSCON->ICR=SYSCON_ICR_RST;
	SYSCON->RISR=SYSCON_RISR_RST;	
	SYSCON->ISR=SYSCON_ISR_RST;
	SYSCON->RSR=SYSCON_RSR_RST;
	SYSCON->EXIRT=SYSCON_EXIRT_RST;
	SYSCON->EXIFT=SYSCON_EXIFT_RST;
	SYSCON->EXIER=SYSCON_EXIER_RST;
	SYSCON->EXIDR=SYSCON_EXIDR_RST;
	SYSCON->EXIMR=SYSCON_EXIMR_RST;
	SYSCON->EXIAR=SYSCON_EXIAR_RST;
	SYSCON->EXICR=SYSCON_EXICR_RST;
	SYSCON->EXIRS=SYSCON_EXIRS_RST;
	SYSCON->IWDCR=SYSCON_IWDCR_RST;
	SYSCON->IWDCNT=SYSCON_IWDCNT_RST;
	SYSCON->IWDEDR=SYSCON_IWDEDR_RST;
	//SYSCON->CINF0=SYSCON_CINF0_RST;
	//SYSCON->CINF1=SYSCON_CINF1_RST;
	//SYSCON->FINF0=SYSCON_FINF0_RST;
	//SYSCON->FINF1=SYSCON_FINF1_RST;
	SYSCON->ERRINF=SYSCON_ERRINF_RST;
}
/*************************************************************/
//SYSCON General Control
//EntryParameter:NewState:,ENDIS_X
//NewState:ENABLE,DISABLE
//ENDIS_X:ENDIS_ISOSC,ENDIS_IMOSC,ENDIS_EMOSC,ENDIS_IDLE_PCLK,ENDIS_SYSTICK,ENDIS_EM_CM,ENDIS_EM_CMRST
//ReturnValue:NONE
/*************************************************************/  
void SYSCON_General_CMD(FunctionalStatus NewState, SYSCON_General_CMD_TypeDef ENDIS_X )
{
	if (NewState != DISABLE)
	{
		if(ENDIS_X==ENDIS_EMOSC) 
		GPIOA0->CONLR=(GPIOA0->CONLR & 0XFFFFF00F)|0x00000440;					//使能对应PIN
		SYSCON->GCER=ENDIS_X;													//enable SYSCON General Control
		while(!(SYSCON->GCSR&ENDIS_X));											//check  Enable?	
		switch(ENDIS_X)
		{
			case ENDIS_IMOSC:
				while(!SYSCON_IMOSCSTFlag); 
				SYSCON_IMOSCSTFlag=0;				// Wait IMOSC stable interrupt
				break;
			case ENDIS_EMOSC:
				while(!SYSCON_EMOSCSTFlag); 
				SYSCON_EMOSCSTFlag=0;				// Wait EMOSC stable interrupt	
				break;	
			case ENDIS_ISOSC:
				while(!SYSCON_ISOSCSTFlag); 
				SYSCON_ISOSCSTFlag=0;				// Wait ISOS stable interrupt	
				break;
			case ENDIS_IDLE_PCLK:
				break;
			case ENDIS_SYSTICK:
				break;
			case ENDIS_EM_CM:
				break;
			case ENDIS_EM_CMRST:
				break;
		}
	}
	else
	{
		SYSCON->GCDR=ENDIS_X;													//disable SYSCON General Control
		while(SYSCON->GCSR&ENDIS_X);											//check  Disable?
	}
}
/*************************************************************/
//Seleted system clk and seleted clk div
//EntryParameter:SYSCLK_X,HCLK_DIV_X,PCLK_DIV_X
//SYSCLK_X:SYSCLK_IMOSC,SYSCLK_EMOSC,SYSCLK_ISOSC
//HCLK_DIV_X:HCLK_DIV_1/2/3/4/5/6/7/8/12/16/24/32/64/128/256
//PCLK_DIV_X:PCLK_DIV_1,PCLK_DIV_2,PCLK_DIV_4,PCLK_DIV_8,PCLK_DIV_16
//ReturnValue:NONE
/*************************************************************/ 
void SystemCLK_HCLKDIV_PCLKDIV_Config(SystemCLK_TypeDef SYSCLK_X , SystemCLK_Div_TypeDef HCLK_DIV_X , PCLK_Div_TypeDef PCLK_DIV_X)
{
	SYSCON->SCLKCR=SYSCLK_KEY | HCLK_DIV_X| SYSCLK_X;
	while(!SYSCON_SYSCLKSTFlag);												//Wait clock switch stable interrupt
	SYSCON_SYSCLKSTFlag=0;
	SYSCON->PCLKCR=PCLK_KEY|PCLK_DIV_X;											//PCLK DIV 1 2 4 6 8 16		
	while(SYSCON->PCLKCR!=PCLK_DIV_X);											//Wait PCLK DIV
	if(SYSCLK_X==SYSCLK_EMOSC) GPIOA0->CONLR=(GPIOA0->CONLR & 0XFFFFF00F)|0x00000440;					//使能对应PIN
}
/*************************************************************/
//WDT enable and disable 
//EntryParameter:,NewState
//NewState:ENABLE,DISABLE
//ReturnValue:NONE
/*************************************************************/
void SYSCON_WDT_CMD(FunctionalStatus NewState)
{
	if(NewState != DISABLE)
	{
		SYSCON->IWDEDR=IWDTEDR_KEY|Enable_IWDT;
		while(!(SYSCON->IWDCR&Check_IWDT_BUSY));
	}
	else
	{
		SYSCON->IWDEDR=IWDTEDR_KEY|Disable_IWDT;
		while(SYSCON->IWDCR&Check_IWDT_BUSY);
	}
}
/*************************************************************/
//Read WDT_CNT
//EntryParameter:NONE
//ReturnValue:IWDCNT
/*************************************************************/
U32_T SYSCON_GET_IWDCNT(void )
{
	return (SYSCON->IWDCNT&0x3FFFFF);
}
/*************************************************************/
//Read IWDT_CLR statue
//EntryParameter:NONE
//ReturnValue: WDT clr flag
/*************************************************************/
B_T SYSCON_GET_IWDT_CLRBSY(void)					
{
	if(SYSCON->IWDCNT&0x80000000)
	{
		return 1;
	}
	else return 0;
}
/*************************************************************/
//reload WDT CN
//EntryParameter:NONE
//ReturnValue: NONE
/*************************************************************/
void SYSCON_IWDCNT_Reload(void)
{
	SYSCON->IWDCNT=CLR_IWDT;
}
/*************************************************************/
//IWDCNT Config
//EntryParameter:NewStateE_IWDT_SHORT,IWDT_TIME_X,IWDT_INTW_DIV_X
//NewStateE_IWDT_SHORT:ENABLE_IWDT_SHORT,DISABLE_IWDT_SHORT
//IWDT_TIME_X:IWDT_TIME_128MS,IWDT_TIME_256MS,IWDT_TIME_500MS,IWDT_TIME_1S,IWDT_TIME_2S,IWDT_TIME_3S,IWDT_TIME_4S,IWDT_TIME_8S
//IWDT_INTW_DIV_X:IWDT_INTW_DIV_7/6/5/4/3/2/1
//ReturnValue: NONE
/*************************************************************/
/*void SYSCON_IWDCNT_Config(IWDT_SHORT_TypeDef NewStateE_IWDT_SHORT , IWDT_TIME_TypeDef IWDT_TIME_X , IWDT_TIMEDIV_TypeDef IWDT_INTW_DIV_X )
{
	SYSCON->IWDCR=IWDT_KEY|NewStateE_IWDT_SHORT|IWDT_TIME_X|IWDT_INTW_DIV_X;
}*/
void SYSCON_IWDCNT_Config(IWDT_TIME_TypeDef IWDT_TIME_X , IWDT_TIMEDIV_TypeDef IWDT_INTW_DIV_X )
{
	SYSCON->IWDCR=IWDT_KEY|IWDT_TIME_X|IWDT_INTW_DIV_X;
}
/*************************************************************/
//LVD Config  and set LVD INT
//EntryParameter:X_LVDEN,INTDET_LVL_X,RSTDET_LVL_X,X_LVD_INT
//X_LVDEN:ENABLE_LVDEN,DISABLE_LVDEN
//INTDET_LVL_X:INTDET_LVL_2_5V,INTDET_LVL_3_0V,INTDET_LVL_3_9V,INTDET_LVL_4_1V
//RSTDET_LVL_X:RSTDET_LVL_2_2V,RSTDET_LVL_2_7V,RSTDET_LVL_3_3V,RSTDET_LVL_3_6V
//X_LVD_INT:ENABLE_LVD_INT,DISABLE_LVD_INT
//ReturnValue: NONE
/*************************************************************/
void SYSCON_LVD_Config(X_LVDEN_TypeDef X_LVDEN , INTDET_LVL_X_TypeDef INTDET_LVL_X , RSTDET_LVL_X_TypeDef RSTDET_LVL_X , X_LVD_INT_TypeDef X_LVD_INT)
{
	SYSCON->LVDCR=LVD_KEY;
	SYSCON->LVDCR=LVD_KEY|X_LVDEN|INTDET_LVL_X|RSTDET_LVL_X|X_LVD_INT;
}
/*************************************************************/
//LVR disable
//EntryParameter:NONE
//ReturnValue: NONE
/*************************************************************/
void LVR_Disable(void)
{
	SYSCON->LVDCR = (SYSCON->LVDCR&0xfffffff0)|LVD_KEY|0x0a;
}
/*************************************************************/
//LVD Enable
//EntryParameter:NONE
//ReturnValue: NONE
/*************************************************************/
void LVR_Enable(void)
{
	SYSCON->LVDCR = (SYSCON->LVDCR&0xfffffff0)|LVD_KEY;
}
/*************************************************************/
//LVD INT ENABLE.
//EntryParameter:NONE
//ReturnValue: NONE
/*************************************************************/
void LVD_Int_Enable(void)
{
	SYSCON->IECR  |= LVD_INT_ST;
}
/*************************************************************/
//LVD INT DISABLE.
//EntryParameter:NONE
//ReturnValue: NONE
/*************************************************************/
void LVD_Int_Disable(void)
{
	SYSCON->IDCR  |= LVD_INT_ST;
}
/*************************************************************/
//external trigger  Mode Selection Functions
//EntryParameter:NewState,EXIPIN,EXI_tringer_mode
//NewState:ENABLE,DISABLE
//EXIPIN:EXI_PIN0/1/2/3/4/5/6/7/8/9/10/11/12/13
//EXI_tringer_mode:_EXIRT,_EXIFT
//ReturnValue: LVD detection flag
/*************************************************************/
void EXTI_trigger_CMD(FunctionalStatus NewState , SYSCON_EXIPIN_TypeDef  EXIPIN , EXI_tringer_mode_TypeDef EXI_tringer_mode)
{
	switch(EXI_tringer_mode)
	{
		case _EXIRT:
			if(NewState != DISABLE)
			{
				SYSCON->EXIRT |=EXIPIN;
			}
			else
			{
				SYSCON->EXIRT &=~EXIPIN;	
			}
			break;
		case _EXIFT:
			if(NewState != DISABLE)
			{
				SYSCON->EXIFT |=EXIPIN;
			}
			else
			{
				SYSCON->EXIFT &=~EXIPIN;	
			}
			break;
	}	
}
/*************************************************************/
//external interrupt enable and disable 
//EntryParameter:NewState,EXIPIN,* GPIOX
//* GPIOX:GPIOA,GPIOB
//EXIPIN:EXI_PIN0/1/2/3/4/5/6/7/8/9/10/11/12/13
//NewState:ENABLE,DISABLE
//ReturnValue:NONE
/*************************************************************/
void EXTI_interrupt_CMD(FunctionalStatus NewState , SYSCON_EXIPIN_TypeDef  EXIPIN )
{
	if(NewState != DISABLE)
	{
		SYSCON->EXIER|=EXIPIN;								//EXI4 interrupt enable
		while(!(SYSCON->EXIMR&EXIPIN));						//Check EXI4 is enabled or not
		SYSCON->EXICR |=EXIPIN;								// Clear EXI4 status bit
	}
	else
	{
		SYSCON->EXIDR|=EXIPIN;
	}
}
/*************************************************************/
//GPIO EXTI interrupt
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void GPIO_EXTI_interrupt(CSP_GPIO_T * GPIOX,U32_T GPIO_IECR_VALUE)
{
	GPIOX->IECR=GPIO_IECR_VALUE;
}
/*************************************************************/
//外接32.768K晶振做CTC时钟，进入SLEEP模式配置
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void SleepMode_goto_sleep_prg(void)
{
	SYSCON_WDT_CMD(DISABLE);
	SYSCON -> PWRCR = (SYSCON -> PWRCR & 0xFFFF3FE3) | (0xA66Aul<<16) | (0x1<<14) | (0x07<<2);
	SystemCLK_HCLKDIV_PCLKDIV_Config(SYSCLK_EMOSC,HCLK_DIV_1,PCLK_DIV_1);
	//外部晶振做系统时钟
	SYSCON_General_CMD(DISABLE,ENDIS_SYSTICK);
	//关闭 Coret 时钟
	SYSCON_General_CMD(DISABLE,ENDIS_IMOSC);
	//关闭内部主 IRC
	//SYSCON_General_CMD(DISABLE,ENDIS_ISOSC);
	//关闭内部副 IRC
	PCLK_goto_idle_mode();
	//进入深度睡眠模式
}
/*************************************************************/
//外接32.768K晶振做CTC时钟，唤醒Sleep模式配置
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void SleepMode_wakeup_prg(void)
{
	//SYSCON_General_CMD(ENABLE,ENDIS_ISOSC);
	//打开内部 SUB IRC
	SYSCON_General_CMD(ENABLE,ENDIS_SYSTICK);
	//打开 Coret 时钟
	SYSCON_General_CMD(ENABLE,ENDIS_IMOSC);
	//打开内部 MIAN IRC
	SystemCLK_HCLKDIV_PCLKDIV_Config(SYSCLK_IMOSC,HCLK_DIV_1,PCLK_DIV_1);
	//主频率做系统时钟
	SYSCON_WDT_CMD(ENABLE);
	SYSCON_IWDCNT_Reload();
}
/*************************************************************/
//MCU goto SLEEP mode
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void PCLK_goto_idle_mode(void)
{
	asm ("doze");											// Enter sleep mode
}  
/*************************************************************/
//MCU goto SLEEP mode
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void PCLK_goto_deepsleep_mode(void)
{	
	//LVD_Disable();																//上电缺省LVR Enable，Disable LVR	
	SYSCON -> PWRCR = (SYSCON -> PWRCR & 0xFFFFCFFC) | (0xA66Aul<<16) | (0x3<<12) | 0x3 ;
	SYSCON->SCLKCR= (SYSCON -> SCLKCR & 0xFFFFF0FF) | SYSCLK_KEY | HCLK_DIV_2;		//睡眠前HCLK分频必须>=2,否则debug单步跑有问题
	asm ("stop");																	// Enter sleep mode
	SYSCON->SCLKCR= (SYSCON -> SCLKCR & 0xFFFFF0FF) | SYSCLK_KEY | HCLK_DIV_1;		
}  
/*************************************************************/
//SYSCON General Control
//EntryParameter:IMOSC_SETECTE_X
//IMOSC_SETECTE_X:IMOSC_SETECTE_20M,IMOSC_SETECTE_40M
//ReturnValue:NONE
/*************************************************************/  
void SYSCON_IMOSC_SETECTE(IMOSC_SETECTE_TypeDef IMOSC_SETECTE_X)
{		
	SYSCON->SCLKCR=SYSCLK_KEY|SYSCLK_ISOSC;						//内部副振作系统时钟
	SYSCON_General_CMD(DISABLE,ENDIS_IMOSC);					//disalbe IMOSC
	if(IMOSC_SETECTE_X==IMOSC_SETECTE_20M)
	{
		SYSCON->CLCR=(SYSCON->CLCR&0XFF8FFFFF)|(0X00<<22);		//使能内部高频振荡器，选择20M作为主震荡频率
		IFC->CEDR=0X01;
		IFC->MR=0;
	}
	else if(IMOSC_SETECTE_X==IMOSC_SETECTE_40M)
	{
		SYSCON->CLCR=(SYSCON->CLCR&0XFF8FFFFF)|(0x01<<22);		//使能内部高频振荡器，选择40M作为主震荡频率
		IFC->CEDR=0X01;
		IFC->MR=1;
	}
	SYSCON_General_CMD(ENABLE,ENDIS_IMOSC);						//enable IMOSC
}
/*************************************************************/
//ESOSC 32.768 ENABLE
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void SYSON_EMOSC_32k_EN(void)
{
	SYSCON -> PWRCR = ( ((SYSCON -> PWRCR) & 0x0000F0FF) | (0xA66Aul<<16) ) ;
	SYSCON->OSTR=0XAD;
	SYSCON_General_CMD(ENABLE,ENDIS_EMOSC);										//enable EMOSC
}
/*************************************************************/
//EXI0 Interrupt enable
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void EXI0_Int_Enable(void)
{
    INTC_ISER_WRITE(EXI0_INT);    
}

/*************************************************************/
//EXI0 Interrupt enable
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void EXI0_Int_Disable(void)
{
    INTC_ICER_WRITE(EXI0_INT);    
}

/*************************************************************/
//EXI1 Interrupt enable
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void EXI1_Int_Enable(void)
{
    INTC_ISER_WRITE(EXI1_INT);    
}

/*************************************************************/
//EXI1 Interrupt enable
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void EXI1_Int_Disable(void)
{
    INTC_ICER_WRITE(EXI1_INT);    
}

/*************************************************************/
//EXI2 Interrupt enable
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void EXI2_Int_Enable(void)
{
    INTC_ISER_WRITE(EXI2_INT);    
}

/*************************************************************/
//EXI2 Interrupt enable
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void EXI2_Int_Disable(void)
{
    INTC_ICER_WRITE(EXI2_INT);    
}

/*************************************************************/
//EXI3 Interrupt enable
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void EXI3_Int_Enable(void)
{
    INTC_ISER_WRITE(EXI3_INT);    
}

/*************************************************************/
//EXI3 Interrupt enable
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void EXI3_Int_Disable(void)
{
    INTC_ICER_WRITE(EXI3_INT);    
}

/*************************************************************/
//EXI4 Interrupt enable
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void EXI4_Int_Enable(void)
{
    INTC_ISER_WRITE(EXI4_INT);    
}

/*************************************************************/
//EXI4 Interrupt enable
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void EXI4_Int_Disable(void)
{
    INTC_ICER_WRITE(EXI4_INT);    
}
/*************************************************************/
//EXI0 Wake up enable
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void EXI0_WakeUp_Enable(void)
{
    INTC_IWER_WRITE(EXI0_INT);    
}

/*************************************************************/
//EXI0 Wake up enable
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void EXI0_WakeUp_Disable(void)
{
    INTC_IWDR_WRITE(EXI0_INT);    
}

/*************************************************************/
//EXI1 Wake up enable
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void EXI1_WakeUp_Enable(void)
{
    INTC_IWER_WRITE(EXI1_INT);    
}

/*************************************************************/
//EXI1 Wake up enable
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void EXI1_WakeUp_Disable(void)
{
    INTC_IWDR_WRITE(EXI1_INT);    
}

/*************************************************************/
//EXI2 Wake up enable
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void EXI2_WakeUp_Enable(void)
{
    INTC_IWER_WRITE(EXI2_INT);    
}

/*************************************************************/
//EXI2 Wake up enable
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void EXI2_WakeUp_Disable(void)
{
    INTC_IWDR_WRITE(EXI2_INT);    
}

/*************************************************************/
//EXI3 Wake up enable
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void EXI3_WakeUp_Enable(void)
{
    INTC_IWER_WRITE(EXI3_INT);    
}

/*************************************************************/
//EXI3 Wake up enable
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void EXI3_WakeUp_Disable(void)
{
    INTC_IWDR_WRITE(EXI3_INT);    
}

/*************************************************************/
//EXI4 Wake up enable
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void EXI4_WakeUp_Enable(void)
{
    INTC_IWER_WRITE(EXI4_INT);    
}

/*************************************************************/
//EXI4 Wake up enable
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void EXI4_WakeUp_Disable(void)
{
    INTC_IWDR_WRITE(EXI4_INT);    
}

/*************************************************************/
//SYSCON Interrupt enable
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void SYSCON_Int_Enable(void)
{
    INTC_ISER_WRITE(SYSCON_INT);    
}

/*************************************************************/
//SYSCON Interrupt enable
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void SYSCON_Int_Disable(void)
{
    INTC_ICER_WRITE(SYSCON_INT);    
}
/*************************************************************/
//SYSCON Wake up enable
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void SYSCON_WakeUp_Enable(void)
{
    INTC_IWER_WRITE(SYSCON_INT);    
}

/*************************************************************/
//SYSCON Wake up disable
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void SYSCON_WakeUp_Disable(void)
{
    INTC_IWDR_WRITE(SYSCON_INT);    
}

/*************************************************************/
//Software_Reset
//EntryParameter:None
//ReturnValue:MCU reset
/*************************************************************/
void SYSCON_Software_Reset(void)
{
	SYSCON->IDCCR=IDCCR_KEY|SWRST;
}
/*************************************************************/
//Interrupt Priority setting
//EntryParameter:00/40/80/C0
//Coret_INT   IQR0
//SYSCON_INT  IQR1
//IFC_INT     IRQ2
//ADC_INT     IRQ3
//GTC0_INT    IRQ4
//GTC1_INT    IRQ5
//GTC2_INT    IRQ6
//EXI0_INT    IRQ7
//EXI1_INT    IRQ8
//GTC3_INT    IRQ9
//UART0_INT   IRQ13
//UART1_INT   IRQ14
//I2C_INT     IRQ17
//EXI2_INT    IRQ21
//EXI3_INT    IRQ22
//EXI4_INT    IRQ23
//CA_INT      IRQ24
//TKEY0_INT   IRQ25
//TKEY1_INT   IRQ26
//LED_INT 	  IRQ27
//ReturnValue:None
/*************************************************************/
void SYSCON_INT_Priority(void)
{
	INTC_IPR0_WRITE(0X00000000);   //IQR0-3
	INTC_IPR1_WRITE(0X00000000);   //IQR4-7  
	INTC_IPR2_WRITE(0X00000000);   //IQR8-11  
	INTC_IPR3_WRITE(0X00000000);   //IQR12-15  
	INTC_IPR4_WRITE(0X00000000);   //IQR16-19  
	INTC_IPR5_WRITE(0X00000000);   //IQR20-23 
	INTC_IPR6_WRITE(0X00000000);   //IQR24-27  
	INTC_IPR7_WRITE(0X00000000);   //IQR28-31
}
/******************* (C) COPYRIGHT 2018 APT Chip *****END OF FILE****/

